package com.thoughtworks.answer;

import java.io.IOException;
import java.util.List;

import com.thoughtworks.exception.GrammerException;
import com.thoughtworks.model.Constants;
import com.thoughtworks.model.Edge;
import com.thoughtworks.model.Question;
import com.thoughtworks.util.ParseInputUtil;
import com.thoughtworks.util.ParseQuestionUtil;
import com.thoughtworks.exception.GrammerException;
import com.thoughtworks.model.Constants;
import com.thoughtworks.model.Edge;
import com.thoughtworks.model.Question;
import com.thoughtworks.util.ParseInputUtil;
import com.thoughtworks.util.ParseQuestionUtil;
public abstract class AbstractAnswer {
	protected List<Edge> allEdges = null;
	
	protected List<Question> questions = null;
	
	public AbstractAnswer() {
		init();
	}
	
	protected void init() {
		try {
			allEdges = ParseInputUtil.getEdgeList(Constants.INPUT_FILE);
			questions = ParseQuestionUtil.geQuestions(Constants.QUESTION_FILE);
		} catch (IOException e) {
			System.err.println("Input.txt or Question.txt not found!");
			System.exit(-1);
		} catch (GrammerException e) {
			System.err.println("Grammer of question is not correct!");
			System.exit(-2);
		}
	}
	
	public void answer(){
		int question_index = 0;
		for(Question question : questions){
			System.out.print("Output #" + (++question_index) + ": ");
			switch (question.getQuestionType()) {
			case DISTANCE_OF_FIX_TRIP:
				distance_of_fix_trip(question);
				break;
			case SHORTEST_DISTANCE_OF_TRIP:
				shortest_distance_of_trip(question);
				break;
			case SHORTEST_STOP_COUNT_OF_TRIP:
				shortest_stop_count_of_trip(question);
				break;
			case COUNT_OF_TRIP_AS_STOP_COUNT_CONDITION:
				count_of_trip_as_stop_count_condition(question);
				break;
			case COUNT_OF_TRIP_AS_DISTANCE_CONDITION:
				count_of_trip_as_distance_condition(question);
				break;
			default:
				break;
			}
		}
	}
	
	protected abstract void distance_of_fix_trip(Question question);
	
	protected abstract void shortest_distance_of_trip(Question question);
	
	protected abstract void shortest_stop_count_of_trip(Question question);
	
	protected abstract void count_of_trip_as_stop_count_condition(Question question);
	
	protected abstract void count_of_trip_as_distance_condition(Question question);
}
